package com.example.testgallery;

import java.util.List;

import android.R.color;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MyAdapter extends BaseAdapter{
	
	private List<String> mlist;
	private Context context;
	private int temp;
	
	
	public MyAdapter() {
		super();
	}
	
	public MyAdapter(List<String> mlist, Context context) {
		super();
		this.mlist = mlist;
		this.context = context;
	}

	public void setRest(int temp){
		this.temp = temp;
	}
	

	@Override
	public int getCount() {
		return mlist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mlist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHodler hodler = null;
		if(convertView==null){
			hodler = new ViewHodler();
			convertView = LayoutInflater.from(context).inflate(R.layout.item, null);	
			hodler.text = (TextView) convertView.findViewById(R.id.text);
			convertView.setTag(hodler);
		}else{
			hodler = (ViewHodler) convertView.getTag();
		}
		
		hodler.text.setText(mlist.get(position));
		if(temp==position){
			hodler.text.setTextColor(Color.rgb(0, 255, 255));
		}else{
			hodler.text.setTextColor(Color.rgb(255, 0, 255));
		}
		
		
		return convertView;
	}
	
	private static class ViewHodler{
		TextView text;
	}
}
